package com.zjc.yohoshop.mvp.persenter;

import com.zjc.lib_core.mvp.presenter.BasePresenter;
import com.zjc.yohoshop.bean.SeeCategoryEntity;
import com.zjc.yohoshop.mvp.contract.SeeFragmentContract;

import org.json.JSONException;
import org.json.JSONObject;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class SeeFragmentPresenter extends BasePresenter<SeeFragmentContract.SeeFragmentIView, SeeFragmentContract.SeeFragmentIModel> {
    @Inject
    public SeeFragmentPresenter(SeeFragmentContract.SeeFragmentIView seeFragmentIView, SeeFragmentContract.SeeFragmentIModel seeFragmentIModel) {
        super(seeFragmentIView, seeFragmentIModel);
    }

    public void request(){
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("menuid", "1");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        m.seeCategort(jsonObject.toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<SeeCategoryEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        v.showDialog();
                        disposable.add(d);
                    }

                    @Override
                    public void onNext(SeeCategoryEntity seeCategoryEntity) {
                        v.hideDialog();
                        v.success(seeCategoryEntity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        v.hideDialog();
                        v.showMessage(e.toString());
                    }

                    @Override
                    public void onComplete() {
                        v.hideDialog();
                    }
                });

    }

}
